<%-- 
    Document   : doRegister
    Created on : 31/03/2011, 09:49:21 PM
    Author     : Jhon
--%>

<%@page import="HTML.*"%>
<%@page import="vo.VOUser"%>
<%@page import="control.Controller"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<% String handleR = request.getParameter("handleR");
   String paswdR = request.getParameter("paswdR");
   String paswdcon = request.getParameter("paswdcon");
   String firstname = request.getParameter("firstname");
   String lastname = request.getParameter("lastname");
   String email = request.getParameter("email");
   String ins = request.getParameter("ins");
   String country = request.getParameter("country");
   String team = request.getParameter("team");
   String mensaje="";
   boolean bien=true;
   if(handleR==null || handleR.isEmpty()){
    mensaje+="handle it's empty <br>";
    bien=false;
   }
   if(paswdR==null || paswdR.isEmpty()){
    mensaje+="password it's empty<br>";
    bien=false;
   }
   if(paswdcon==null || paswdcon.isEmpty()){
    mensaje+="confirm password it's empty<br>";
    bien=false;
   }
   if(firstname==null || firstname.isEmpty()){
    mensaje+="First Name it's empty<br>";
    bien=false;
   }
   if(lastname==null || lastname.isEmpty()){
    mensaje+="Last Name it's empty<br>";
    bien=false;
   }
   if(email==null || email.isEmpty()){
    mensaje+="Email it's empty<br>";
    bien=false;
   }
   if(ins==null || ins.isEmpty()){
    mensaje+="Institution it's empty<br>";
    bien=false;
   }
   if(country==null || country.isEmpty()){
    mensaje+="Country it's empty<br>";
    bien=false;
   }
   if(!paswdR.equals(paswdcon)){
    mensaje+="passwords doesn't match <br>";
    bien=false;
   }
   HtmlBody b = new HtmlBody("Register new User");
   Controller co = Controller.getInstance();
   if(bien){
   VOUser u = new VOUser();
   u.setEmail(email);
   u.setFirstName(firstname);
   u.setHandle(handleR);
   u.setLastName(lastname);
   u.setPassword(paswdcon);
   u.setCountry(country);
   u.setInstitution(ins);
   u.setIsAdmin(false);
   u.setTeam(team);
   try{
   co.register(u);
   }catch(Exception e){
    mensaje+=e.getMessage();
    bien=false;
   }
   if(bien){
           session.setAttribute("USER",co.findUser(handleR));
           response.sendRedirect("../User/UserIndex.jsp");
           return;

   }else{
    HtmlContent c = new HtmlContent("Registro");
    HtmlSideBar s = new HtmlSideBar(false);
    c.addTitleImage("UPSS!!!", "There  is a problem with: <br>"+mensaje, "CaraTriste.jpg", "120", "120");
    c.addRegister();
    b.addContent(c.getContent());
    b.addSideBar(s.getBar());
   }
   }else{
    HtmlContent c = new HtmlContent("Registro");
    HtmlSideBar s = new HtmlSideBar(false);
   c.addTitleImage("UPSS!!!", "There  is a problem with: <br>"+mensaje, "CaraTriste.jpg", "120", "120");
   c.addRegister();
    b.addContent(c.getContent());
    b.addSideBar(s.getBar());
   }

%>

    <%=b.getHtml()%>